package com.xuetang9.t9.hotel.mapper;


import com.xuetang9.t9.hotel.beans.Floor;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Pang
 */
@Repository
public interface IFloorMapper {

    /**
     * 添加楼层
     * @param floor
     * @return
     */
    @Insert("INSERT INTO g_floor(floor_name,floor_comm) VALUES(#{floorName},#{floorComm})")
    int insert(Floor floor);


    /**
     * 删除楼层
     * @param id
     * @return
     */
    @Delete("DELETE FROM g_floor WHERE floor_id=#{id}")
    int delete(Integer id);


    /**
     * 修改楼层
     * @param floor
     * @return
     */
    @Update("UPDATE g_floor SET floor_name=#{floorName},floor_comm=#{floorComm} WHERE floor_id=#{floorId}")
    int update(Floor floor);


    /**
     * 查询全部楼层（附加）
     * @return
     */
    @Select("SELECT * FROM g_floor")
    @Results(value = {
            @Result(id = true,column = "floor_id", property = "floorId"),

            @Result(column = "floor_id", property = "rooms",many = @Many(select = "com.xuetang9.t9.hotel.mapper.IRoomInfoMapper.selectBtFloorId",fetchType = FetchType.EAGER))
    })
    List<Floor> selectByAll();


    /**
     * 获取全部楼层
     * @return
     */
    @Select("SELECT * FROM g_floor")
    List<Floor> selectByFloorAll();


    /**
     * 查询某个楼层
     * @param id
     * @return
     */
    @Select("SELECT * FROM g_floor WHERE floor_id=#{id}")
    Floor selectById(Integer id);
}
